package com.ffs.fsm.thread;

import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * 线程工厂
 * @author ffs80 created 2021/7/9
 */
public class PoolThreadFactory implements ThreadFactory {
    /**
     * 线程计数
     */
    private AtomicInteger count = new AtomicInteger(0);
    /**
     * 线程明
     */
    private String name;

    public PoolThreadFactory(String name) {
        this.name = name;
    }

    @Override
    public Thread newThread(Runnable r) {
        int curCount = count.incrementAndGet();
        Thread thread = new Thread(r,name+"-"+curCount);
        return thread;
    }
}
